package creationPattern.Factory.Factory_01.controller;

import creationPattern.Factory.Factory_01.entity.AwardInfo;
import creationPattern.Factory.Factory_01.entity.DiscountResult;
import creationPattern.Factory.Factory_01.entity.SmallGiftInfo;
import creationPattern.Factory.Factory_01.service.DiscountService;
import creationPattern.Factory.Factory_01.service.SmallGiftService;
import creationPattern.Factory.Factory_01.service.YouKuMemberService;

import java.util.UUID;

/**
 * 发放奖品操作
 */
public class DeliverController {
    /**
     * 按照类型的不同发放奖品
     * 奖品类型 1-打折券 2-优酷会员 3-小礼品
     * @param awardInfo
     */
    public void awardToUser(AwardInfo awardInfo){
        Integer awardType = awardInfo.getAwardType();
        switch (awardType){
            case 1:
                // 打折券
                DiscountService discountService = new DiscountService();
                DiscountResult discountResult = discountService.sendDiscount(awardInfo.getuId(), awardInfo.getAwardNumber());
                System.out.println(discountResult);
                break;
            case 2:
                // 优酷会员
                YouKuMemberService youKuMemberService = new YouKuMemberService();
                youKuMemberService.openMember(awardInfo.getExtMap().get("phone"), awardInfo.getAwardNumber());
                System.out.println("优酷会员发放成功");
                break;
            case 3:
                // 小礼品
                SmallGiftService smallGiftService = new SmallGiftService();
                SmallGiftInfo smallGiftInfo = new SmallGiftInfo();
                smallGiftInfo.setUserName(awardInfo.getExtMap().get("userName"));
                smallGiftInfo.setAddress(awardInfo.getExtMap().get("address"));
                smallGiftInfo.setOrderId(String.valueOf(UUID.randomUUID()));
                smallGiftInfo.setUserPhone(awardInfo.getExtMap().get("phone"));
                Boolean aBoolean = smallGiftService.giveSmallGift(smallGiftInfo);
                System.out.println(aBoolean + ":" + "小礼品发放成功");
        }
    }
}
